DROP PROCEDURE IF EXISTS add_tb_column;
DELIMITER $$
CREATE PROCEDURE add_tb_column()
BEGIN
DECLARE  CurrentDatabase VARCHAR(100);
SELECT DATABASE() INTO CurrentDatabase;
<#if tableList??&&(tableList?size>0)>
    <#list tableList as t>
        <#if t.tableColumns??&&(t.tableColumns?size>0)>
            <#list t.tableColumns as column>
                begin
                IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS  WHERE   TABLE_SCHEMA=CurrentDatabase
                AND TABLE_NAME='${t.name}'
                AND COLUMN_NAME='${column.columnName}' )
                THEN
                ALTER TABLE ${t.name} ADD COLUMN  ${column.columnName} ${column.columnMySQLType()}
                <#if column.columnLength??&&column.columnLength!="">
                     (${column.columnLength}
                </#if>
                <#if column.columnPrecision??&&column.columnPrecision!="">
                     ,${column.columnPrecision})
                <#elseif column.columnLength??&&column.columnLength!="" >
                     )
                </#if>
                <#if column.columnDefault??&&column.columnDefault!="">
                     default ${column.columnDefault}
                </#if>
                <#if column.getNullable()>
                     NOT NULL
                </#if>
                <#if column.columnAnnotation??&&column.columnAnnotation!="">
                     COMMENT ' ${column.columnAnnotation} ';
                </#if>
                END IF;
                END;
            </#list>
        </#if>

    </#list>
</#if>
END;
CALL add_tb_column;
DROP PROCEDURE add_tb_column;

$$